﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Globalization;
using MJB.UI.ContentEditor.Document;

namespace MJB.UI.ContentEditor.Converters
{
    /// <summary>
    /// Converts a numbers sign from positive to negative, and vice versa.
    /// </summary>
    public class OppositeSignConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// Converts a number to its negative.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value is Int32)
                return -System.Convert.ToInt32(value);

            if(value is Double)
                return -System.Convert.ToDouble(value);

            return value;

        }

        /// <summary>
        /// Does the same thing as Convert.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value is Int32)
                return -System.Convert.ToInt32(value);

            if(value is Double)
                return -System.Convert.ToDouble(value);

            return value;
        }

        #endregion
    }

}
